#pragma once

#include <QWidget>
#include <vector>
#include "BondDetailPrimarySimilarData.h"
#include "../BondColDelegate.h"

class SVirtualTable;
class DefaultTableModel;
class STableColumnSet;
class QTableView;
class CSSVContainer;
enum { emHolidayNull = 0, emHolidayCib, emHolidaySSE };
struct SortInfo {
	bool	bReLoad;
	bool	bSort;
	int		nSortCol;
	int		nPreSortCol;
	int		nSort; //-1 不排序 0 降序 1 升序
	int		sortKey;
	char    czKey[50];
	SortInfo() {
		nSortCol = -1;
		bSort = false;
		nSort = -1;
		nPreSortCol = -1;
		sortKey = CBondContainer::BOND_NULL;
		memset(czKey, 0, sizeof(czKey));
	}
};

enum  tabType {
	relevanceIssure = 0,	    //同发行人
	relevanceSecond,			//相似二级
	relevanceFirst,				//相似一级
	relevanceNumber = 4
};

class BondDetailPrcFilterList : public QWidget
{
	Q_OBJECT
public:
	BondDetailPrcFilterList(QWidget* p);
	void UpdateResult(int currentType,std::vector<BrokerKey> &vctBondValid);
	void setBrokerKey(int nID, const char* cBroker);
	void updatePrcTable();

protected:
	virtual void updateTable(bool reset) = 0;
	void initListTitle();
	void sortCurrent(VSortKey sortKey, bool bSort, std::vector<BrokerKey>& vcrCurrentBondValid);
	void getIssurerType(CBondInfo* pInfo , QString & strType);

public slots:
	void onBestPricePush(QList<xQBBestPriceUnit_c> list);
	void onDealMarketPushAll(int funid,QList<xQBMarketStreamUnit_c> marketList);

Q_SIGNALS:
	void bondSelected(std::string);

protected slots:
	void onHeaderSort(int col);
	void onTableRowDblClicked(const QModelIndex& index);
	void onTableRowClicked(const QModelIndex& index);

protected:
	SVirtualTable*			m_table = nullptr;
	STableColumnSet*		m_tableSet = nullptr;
	DefaultTableModel*		m_model = nullptr;
	std::vector<int>		m_cols;
	CSortInfoManager		m_sortinfoManager;
	SortInfo				m_sortInfo;
	std::vector<BrokerKey>			m_CurrentBondValid;
	std::vector<QString>			m_CurrentBondKeys;
	tabType					m_ntabType;
	BrokerKey				m_nbrokerKey;
	const int				m_gErrorBroker = -1;//全部没有报价时显示--
	bool					m_bfirstClicked = false;
};

//同发行人
class SameIssurerList : public BondDetailPrcFilterList
{
public:
	SameIssurerList(QWidget* p);
	enum emIssureCol {
		priCol_RESTIME = 0,			//剩余期限
		priCol_CODE,				//代码
		priCol_NAME,				//简称
		priCol_BID,					//Bid
		priCol_OFR,					//Ofr
		priCol_DEALPRICE,			//成交价
		priCol_COUPONRATE,			//票面利率
		priCol_ISSUREDAY,			//发行日
		priCol_BONDRATE,			//主/债
		priCol_CDC,					//中债估值
		priCol_UPDATETIME			//更新时间

	};
	void updateTable(bool reset) override;
private:
	void initTable();
	const int m_gIssuerListNumb = 11;
};

//相似二级
class RelevanceSecondList : public BondDetailPrcFilterList
{
public:
	RelevanceSecondList(QWidget* p);
	enum emReSecondCol {
		rSeCol_RESTIME = 0,			//剩余期限
		rSeCol_CODE,				//代码
		rSeCol_NAME,				//简称
		rSeCol_BID,					//Bid
		rSeCol_OFR,					//Ofr
		rSeCol_DEALPRICE,			//成交价
		rSeCol_ISSURERTNG,			//估值
		rSeCol_COMPANYTYPE,			//企业类型
		rSeCol_BONDRATE,			//主/债
		rSeCol_UPDATETIME			//更新时间

	};
	void updateTable(bool reset) override;
private:
	void initTable();
};

//相似一级
class RelevanceFirstList : public BondDetailPrcFilterList
{
public:
	RelevanceFirstList(QWidget* p);
	enum emReFirstCol {
		rFCol_CODE = 0,				//代码
		rFCol_NAME,					//简称
		rFCol_MATURITY,				//期限
		rFCol_ISSUREDAY,			//发行日
		rFCol_COUPONRATE,			//票面利率
		rFCol_OFFERINGAMOUNT,		//发行量(亿)
		rFCol_COMPANYTYPE,			//企业类型
		rFCol_ISSURERTNG			//主/债
	};
	void updateTable(bool reset) override;
private:
	void initTable();
};